/*
* Copyright (c) Huawei Technologies Co., Ltd. 2021. All rights reserved.
*/

#ifndef VPC_CMDLIST_PIPELINE_MODULE_H
#define VPC_CMDLIST_PIPELINE_MODULE_H

#ifdef __KERNEL__
#include <linux/types.h>
#else
#include <stdint.h>
#endif

#include "pipeline_define.h"
typedef struct Top {
    uint8_t vpcStart;
    uint32_t in0Height;
    uint32_t in0Width;
    uint32_t in1Height;
    uint32_t in1Width;
    uint32_t outHeight;
    uint32_t outWidth;
    uint32_t out1Height;
    uint32_t out1Width;
    uint32_t out2Height;
    uint32_t out2Width;
    uint32_t in0Format;
    uint32_t in1Format;
    uint32_t outFormat;
    uint32_t out1Format;
    uint32_t out2Format;
    uint32_t bitWidth;
    uint32_t rdChannelSel;
    // add for milanV1R3
    uint32_t out1To3En;
    uint32_t multiLevelZoomEn;

    uint32_t errMask;
    uint32_t pipeIntMerge;
} top_t;

typedef struct VP_RD {
    uint64_t addr;
    uint32_t lineSize;
    uint32_t frameSize;
    uint32_t stride;
    uint8_t  yflipEn;
    uint32_t du;
    uint32_t pixelFmt;
} vp_rd_t;

typedef struct VP_WR {
    uint64_t addr;
    uint32_t stride;
    uint32_t lineSize;
    uint8_t yflipEn;
    uint32_t pixelFmt;
} vp_wr_t;

typedef struct VideoPorts {
    struct VP_RD rd[VP_RD_NUM];
    struct VP_WR wr[VP_WR_NUM];
} video_ports_t;

typedef struct NR_RD {
    uint8_t splitEn;
    uint8_t timeoutTrld;
    uint8_t allocatedDu;
    uint8_t en;
} nr_rd_t;

typedef struct NR_WR {
    uint8_t splitEn;
    uint8_t timeoutTrld;
} nr_wr_t;

typedef struct NonRasterPorts {
    struct NR_RD rd[NR_RD_NUM];
    struct NR_WR wr[NR_WR_NUM];
} nonraster_ports_t;

typedef struct Cvdr {
    struct VideoPorts vp;
    struct NonRasterPorts nr;
} cvdr_t;

typedef struct Cache {
    uint8_t en3d;
    uint8_t sramWrapEn;
    uint32_t runMode;
    uint64_t addr[3];
    uint32_t stride[3];
} cache_t;

typedef struct Rdma {
    uint32_t srcyhAddrL;
    uint32_t srcyhAddrH;
    uint32_t srcchAddrL;
    uint32_t srcchAddrH;
    uint32_t srcyhStride;
    uint32_t srcchStride;
    uint32_t srcyAddrL;
    uint32_t srcyAddrH;
    uint32_t srccAddrL;
    uint32_t srccAddrH;
    uint32_t srcyStride;
    uint32_t srccStride;
} rdma_t;

typedef struct Swap {
    uint8_t en;
    uint32_t inPos;
    uint32_t outPos;
} swap_t;

typedef struct UvUp {
    uint8_t en;
} uvup_t;

typedef struct CscMode {
    uint8_t fpPreOffset;
    uint8_t fpOrder;
    uint8_t fpFmacEn;
    uint8_t yForward;
    uint8_t calCore;
} csc_mode_t;

typedef struct CscCvtMode {
    uint32_t rndModeOut;
    uint32_t rndModeIn;
    uint8_t clipEnOut;
    uint8_t clipEnIn;
} csc_cvt_mode_t;

typedef struct Csc {
    uint8_t en;
    uint8_t alphaPaddingEn;
    uint8_t hi1910CscOut10bEn; // out不存在这一位
    struct CscMode cscMode;
    struct CscCvtMode cvtMode;
    uint32_t coeff[24];
    uint32_t clipThresh[6];
    uint32_t normalizeIn;
    uint32_t normalizeOut;
    uint32_t alpha;
} csc_t;

typedef struct UvDown {
    uint8_t uvCross;
    uint32_t uv444to422Coeff[6];
    // 422to420只有输出有
    uint8_t uv422to420FilteEn;
    uint8_t uv422to420ClipEn;
} uvdown_t;

typedef struct Crop {
    uint32_t hmin;
    uint32_t hmax;
    uint32_t vmin;
    uint32_t vmax;
} crop_t;

typedef struct Padding {
    uint8_t en;
    uint32_t mirrorUvSel;
    uint32_t dirPriority;
    uint32_t mirrorMode;
    uint32_t paddingSel;
    uint32_t bottomSize;
    uint32_t topSize;
    uint32_t rightSize;
    uint32_t leftSize;
    uint32_t inHeight;
    uint32_t inWidth;
    uint32_t regValueHor[3];
    uint32_t regValueVer[3];
} padding_t;

typedef struct Flip {
    uint8_t enX;
    uint8_t enY;
    uint8_t isPreX; // 选择使用prexlip还是postxlip, 不可同时使用
    uint8_t isPreY;
    uint32_t inHeight;
    uint32_t inWidth;
} flip_t;

typedef struct Blend {
    uint8_t en;
    uint32_t blendMode;
    uint32_t lay0InSize;
    uint32_t lay1InSize;
    uint32_t leftPosition;
    uint32_t coefAlpha;
    uint32_t coefBeta;
    uint32_t coefGamma;
} blend_t;

typedef struct Resize {
    uint8_t en;
    uint32_t inHeight;
    uint32_t inWidth;
    uint32_t outHeight;
    uint32_t outWidth;
    uint32_t ihincL;
    uint32_t ihincH;
    uint32_t ivincL;
    uint32_t ivincH;
    uint32_t biasHaL;
    uint32_t biasHaH;
    uint32_t biasHbL;
    uint32_t biasHbH;
    uint32_t biasVaL;
    uint32_t biasVaH;
    uint32_t biasVbL;
    uint32_t biasVbH;
    uint32_t biasHaUvL;
    uint32_t biasHaUvH;
    uint32_t biasHbUvL;
    uint32_t biasHbUvH;
    uint32_t cubicA;
    uint32_t rndCtrl0;
    uint8_t splitEn;
    uint32_t posType;
    uint32_t incType;
    uint32_t incSrc;
    uint32_t biasSrc;
    uint32_t alignMode;
    uint32_t funcType;
    uint32_t indexInLeft;
    uint32_t indexInRight;
    uint32_t indexInTop;
    uint32_t indexInBottom;
    uint32_t indexOutLeft;
    uint32_t indexOutRight;
    uint32_t indexOutTop;
    uint32_t indexOutBottom;
} resize_t;

typedef struct YuvScalerPara {
    int16_t taps4[SCALER_COFF_NB_4];
    int16_t taps6[SCALER_COFF_NB_6];
    int16_t taps8[SCALER_COFF_NB_8];
} yuvscaler_para_t;

typedef struct YuvWPara {
    struct YuvScalerPara scale[2]; // scale 0 - horizontal, scale 1 - vertical
} yuv_wpara_t;

typedef struct YuvScale {
    uint32_t bypass;
    uint32_t ihleftInt;
    uint32_t ihleftDec;
    uint32_t ihrightInt;
    uint32_t ihrightDec;
    uint32_t ivtopInt;
    uint32_t ivtopDec;
    uint32_t ivbotInt;
    uint32_t ivbotDec;
    uint64_t ihinc;
    uint64_t ivinc;
    uint32_t inHeight;
    uint32_t inWidth;
    uint32_t outHeight;
    uint32_t outWidth;
    struct YuvWPara coeff;
} yuvscaler_t;

typedef struct MosaicRegion {
    uint8_t en;
    uint32_t hmin;
    uint32_t hmax;
    uint32_t vmin;
    uint32_t vmax;
} mosaic_region_t;

typedef struct Mosaic {
    uint32_t inWidth;
    uint32_t inHeight;
    uint32_t blockSize;
    struct MosaicRegion mosaicRegion[MOSAIC_REGION_NUM];
} mosaic_t;

typedef struct Rotate {
    uint8_t en;
    uint32_t inHeight;
    uint32_t inWidth;
    uint32_t rotDir;
    uint32_t inPicAddrH[3];
    uint32_t inPicAddrL[3];
    uint32_t inPicStride[3];
    uint32_t outPicAddrH[3];
    uint32_t outPicAddrL[3];
    uint32_t outPicStride[3];
} rotate_t;

typedef struct Point {
    int32_t x;
    int32_t y;
} point_t;

typedef struct CoverRegion {
    uint8_t en;
    uint32_t coverValue;
    int32_t coverkk01;
    int32_t coverkk02;
    int32_t coverkk03;
    int32_t coverkk12;
    int32_t coverkk13;
    int32_t coverkk23;
    struct Point points[4];
} cover_region_t;

typedef struct Cover {
    uint32_t inWidth;
    uint32_t inHeight;
    uint32_t alignMode;
    struct CoverRegion coverRegion[COVER_REGION_NUM];
} cover_t;

typedef struct OsdCsc {
    uint8_t en;
    uint32_t coeff[24]; // 24: csc系数个数
} osd_csc_t;

typedef struct OsdRegion {
    uint8_t en;
    uint32_t osdImgAddrL;
    uint32_t osdImgAddrH;
    uint32_t osdImgStride;
    uint32_t osdImgHeight;
    uint32_t osdImgWidth;
    uint32_t osdHmin;
    uint32_t osdHmax;
    uint32_t osdVmin;
    uint32_t osdVmax;
    uint32_t osdFormat;
    uint32_t osdGlobalAlpha;
    uint32_t osdBitExtMode;
    uint8_t osdAlphaEn;
    uint32_t osdAlpha0;
    uint32_t osdAlpha1;
    uint32_t osdAlphaRev;      // OSD 图像 alpha值反色开关
    uint32_t osdRgbRev;        // OSD 图像 rgb像素值反色开关
    struct OsdCsc osdCsc;
} osd_region_t;

typedef struct Osd {
    uint32_t inWidth;
    uint32_t inHeight;
    uint32_t clut[16];
    struct OsdRegion osdRegion[OSD_REGION_NUM];
} osd_t;

typedef struct Histogram {
    uint8_t en;
    uint8_t isYuvSum;
    uint32_t mode;
    uint32_t readSize;
    uint64_t readAddr;
} histogram_t;

typedef struct Lut {
    uint8_t en;
    uint32_t width;
    uint32_t height;
    uint8_t mapValueYorR[256];
    uint8_t mapValueUorG[256];
    uint8_t mapValueVorB[256];
} lut_t;

typedef struct Filter {
    uint8_t en;
    uint8_t isGaussFun;
    uint8_t needTransFixPoint;
    uint8_t isKernelFp32;
    uint32_t mode;
    uint32_t blurMode;
    uint32_t sortMode;
    uint32_t rndMode;
    uint32_t ksizeX;
    uint32_t ksizeY;
    uint32_t inHeight;
    uint32_t inWidth;
    uint32_t outHeight;
    uint32_t outWidth;
    uint32_t paddingSel;
    uint32_t regValueHor[3];
    uint32_t regValueVer[3];
    uint32_t coeff[25];
    uint32_t scale;
    uint32_t delta;
} filter_t;

typedef struct Hsv {
    uint8_t hueFst;
    uint8_t hueEn;
    uint8_t satEn;
    uint8_t hsv2rgbEn;
    uint8_t rgb2hsvEn;
    uint32_t scaleSat;
    uint32_t deltaHue;
} hsv_t;

typedef struct Convert {
    uint8_t en;
    uint8_t scaleEn;
    uint32_t rnd;
    uint32_t scale;
} convert_t;

typedef struct Enhance {
    uint8_t en;
    uint32_t adder;
    uint32_t multipler;
} enhance_t;

typedef struct Contrast {
    uint8_t en;
    uint32_t para0;
    uint32_t para1;
    uint32_t para2;
    uint32_t para3;
} contrast_t;

typedef struct Transform {
    uint8_t en;
    uint32_t para[3][3];
} transform_t;

typedef struct Normalize {
    uint8_t en;
    uint32_t mode;
    uint32_t scale[3];
    uint32_t delta[3];
} normalize_t;

typedef struct VpcClip {
    uint8_t en;
    uint8_t above;
    uint32_t max[3];
    uint32_t min[3];
    uint32_t cval[3];
    uint32_t mode;
} vpc_clip_t;

typedef struct PixAug {
    struct Enhance enhance;
    struct Contrast contrast;
    struct Transform transform;
    struct Normalize normalize;
    struct VpcClip clip;
} pixaug_t;

typedef struct Affine {
    uint8_t en;
    uint8_t en3d;
    uint32_t coorSel;
    uint32_t rndMode;
    uint32_t dataFmt;
    uint32_t calcMode;
    uint32_t inHeight;
    uint32_t inWidth;
    uint32_t outHeight;
    uint32_t outWidth;
    uint32_t lutAddrL;
    uint32_t lutAddrH;
    uint32_t lutStride;
    uint32_t wrAddrL;
    uint32_t wrAddrH;
    uint32_t wrStride;
    uint32_t blkHeight;
    uint32_t blkWidth;
    uint32_t coeff[12];
    uint32_t inDepth3d;
    uint32_t outDepth3d;
    uint32_t paddingSel;
    uint32_t regValueHor[3];
    uint32_t regValueVer[3];
} affine_t;

#ifdef __cplusplus
#if __cplusplus
extern "C" {
#endif
#endif // #ifdef __cplusplus

void vp_disable(struct VideoPorts *vp);

uint8_t crop_en(struct Crop *crop);
void crop_disable(struct Crop *crop);

uint8_t padding_en(struct Padding *padding);
void padding_disable(struct Padding *padding);

uint8_t flip_en(struct Flip *flip);
void flip_disable(struct Flip *flip);

uint8_t resize_en(struct Resize *resize);
void resize_disable(struct Resize *resize);

uint8_t yuvscaler_en(struct YuvScale *scaler);
void yuvscaler_disable(struct YuvScale *scaler);
void yuvscaler_bypass(struct YuvScale *scaler);

void hsv_disable(struct Hsv *hsv);
uint8_t hsv_en(struct Hsv *hsv);
void affine_disable(struct Affine *affine);
void pixaug_disable(struct PixAug *pixaug);

uint8_t mosaic_en(struct Mosaic *mosaic);
void mosaic_disable(struct Mosaic *mosaic);
uint8_t cover_en(struct Cover *cover);
void cover_disable(struct Cover *cover);
uint8_t osd_en(struct Osd *osd);
void osd_disable(struct Osd *osd);

void csc_disable(struct Csc *csc);

#ifdef __cplusplus
#if __cplusplus
}
#endif
#endif // #ifdef __cplusplus


#endif // #ifndef VPC_CMDLIST_PIPELINE_MODULE_H
